import matplotlib.pyplot as plt
import numpy as np


# 绘制真实数据路线图
def draw_route(cars_list, location, maxp=6):
    # 绘图

    plt.subplots_adjust(bottom=0.15)
    plt.xlabel(u"x")  # X轴标签
    plt.ylabel(u"y")  # Y轴标签

    plt.title("Manchoose Solution")

    m = np.sum(cars_list == 0)

    toshow = np.append(cars_list, 0)
    loc = np.where(toshow == 0)[0]

    for k in range(m):
        # 统计第k行非-1的个数
        showindex = toshow[loc[k]:loc[k + 1] + 1]
        result_x, result_y = location[showindex, 1], location[showindex, 0]
        plt.plot(result_x, result_y, marker='>', mec='r', mfc='w', label=u'Route')
        try:
            plt.axis([
                np.min(location[:, 1]),
                np.max(location[:, 1]),
                np.min(location[:, 0]),
                np.max(location[:, 0])
            ])
        except:
            pass
        if k % maxp == maxp - 1:
            plt.legend()
            plt.show()
    plt.legend()  # 让图例生效
    plt.show()
    plt.close(0)
